gtkwindow: Simplify GTK grab notification
authorCarlos Garnacho <carlosg@gnome.org>
Mon, 17 May 2021 21:44:28 +0000 (23:44 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Mon, 17 May 2021 22:16:48 +0000 (00:16 +0200)
The _gtk_widget_grab_notify() function just (maybe) did a) reset
controllers and b) hide toplevels. The second part was a testing
remnant introduced in commit 024d832d943, not part of the original
fix.

Do the former more concisely, called from the place where we figure
out whether a widget's ability to receive events changed due to
GTK grabs. It's across those changes that we are interested in
resetting the controllers.

With the gestures being reset both ways, GtkWindowHandle (and
probably other) gestures are now able to reset after a GTK grab
takes input away (e.g. GtkMenuButton). This could be seen as
a sudden jump the next time they'd be dragged with the mouse,
as the gesture would "resume" the previous interaction.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/3942
gtk/gtkwidget.c
gtk/gtkwidgetprivate.h
gtk/gtkwindow.c

index c45810a455f95d7bcca950987d20d9bc822be574..a7bdf8b08fc19fcbfb368685e7a3da94a7e5c152 100644 (file)
@@ -748,34 +748,6 @@ gtk_widget_real_contains (GtkWidget *widget,
                                           &GRAPHENE_POINT_INIT (x, y));
 }
 
-/*
- * _gtk_widget_grab_notify:
- * @widget: a `GtkWidget`
- * @was_grabbed: whether a grab is now in effect
- *
- * Emits the `GtkWidget`::grab-notify signal on @widget.
- */
-void
-_gtk_widget_grab_notify (GtkWidget *widget,
-                         gboolean   was_grabbed)
-{
-  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
-  GList *l;
-
-  if (was_grabbed)
-    return;
-
-  for (l = g_list_last (priv->event_controllers); l; l = l->prev)
-    {
-      GtkEventController *controller = l->data;
-
-      gtk_event_controller_reset (controller);
-    }
-
-  if (GTK_IS_NATIVE (widget))
-    gtk_widget_hide (widget);
-}
-
 static void
 gtk_widget_real_root (GtkWidget *widget)
 {
index 4aee55cb6b26fb0f1a8fdc70bd579f2eeeb781c5..2863787e24ce63bad23c56c363e3736677201f7c 100644 (file)
@@ -247,8 +247,6 @@ void              _gtk_widget_set_has_grab                 (GtkWidget *widget,
                                                             gboolean   has_grab);
 
 gboolean          gtk_widget_has_grab                      (GtkWidget *widget);
-void              _gtk_widget_grab_notify                  (GtkWidget *widget,
-                                                            gboolean   was_grabbed);
 
 void              _gtk_widget_propagate_display_changed    (GtkWidget  *widget,
                                                             GdkDisplay *previous_display);
index d7048ed41260a757bb9c5624d129a0b5f6bdcc94..add3caf85eafb002197ab830250bc8f3f9b185d5 100644 (file)
@@ -6732,8 +6732,6 @@ gtk_grab_notify_foreach (GtkWidget *child,
                                          GDK_CROSSING_GTK_UNGRAB);
     }
 
-  _gtk_widget_grab_notify (child, was_shadowed);
-
   g_object_unref (child);
 }
 
@@ -6776,6 +6774,8 @@ gtk_window_propagate_grab_notify (GtkWindow *window,
                                from_grab,
                                was_shadowed,
                                is_shadowed);
+
+      gtk_widget_reset_controllers (l->data);
     }
 
   g_list_free_full (widgets, g_object_unref);